import matplotlib
matplotlib.use("Qt5Agg") # 声明使用Qt5

from PyQt5.QtWidgets import QSizePolicy
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

class FigurePlot(FigureCanvas):
    #连接pyqt5和matplotlib的类
    def __init__(self, width=3.6, heigh=3.8, dpi=100):
        self.figs = Figure(figsize=(width, heigh), dpi=dpi) #创建一个Figure
        super(FigurePlot, self).__init__(self.figs)
        self.axes = self.figs.add_subplot(111)
    
    def LineChart(self, file, key):
        df = pd.read_csv(file, parse_dates=True, index_col = "Date")
        #fig, ax = plt.subplots()
        print(df)
        self.axes.set_title('LineChart')
        self.axes.set_xlabel('Date')
        print(type(key))
        self.axes.plot(df[key])
    
    def RegionalFigure(self, file, key1, key2):
        df = pd.read_csv(file, parse_dates=True, index_col = "Date")
        self.axes.set_title('RegionalFigure')
        self.axes.set_xlabel('Date')
        self.axes.stackplot(df[key1], df[key2])
    
    def Histogram(self, file, key1, key2):
        df = pd.read_csv(file, parse_dates=True, index_col = "Date")
        self.axes.set_title('Histogram')
        self.axes.set_xlabel('Date')
        self.axes.hist2d(df[key1], df[key2])
